package com.gcxy.controller;


import com.gcxy.config.result.R;
import com.gcxy.domain.dto.AddUserDTO;
import com.gcxy.domain.dto.GetIdDTO;
import com.gcxy.domain.dto.UpdateUserDTO;
import com.gcxy.domain.dto.UserPageDTO;
import com.gcxy.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.convert.PeriodUnit;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-02-10
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户管理")
public class UserController {

    @Autowired
    private IUserService userService;

    @PostMapping("/addUser")
    @ApiOperation(value = "新增用户", notes = "新增用户")
    public R addUser(@Validated @RequestBody AddUserDTO addUserDTO) {
        return userService.addUser(addUserDTO);
    }

    @PutMapping("/updateUser")
    @ApiOperation(value = "修改用户", notes = "修改用户")
    public R updateUser(@RequestBody @Validated UpdateUserDTO updateUserDTO) {
        return userService.updateUser(updateUserDTO);
    }

    @GetMapping("/detail")
    @ApiOperation(value = "查询用户详情", notes = "查询用户详情")
    public R getUserDetail(@RequestParam("id") int id) {
        return userService.getUserDetail(id);
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询用户列表", notes = "查询用户列表")
    public R getUserList() {

        return userService.getUserList();
    }

    @PostMapping("/userPage")
    @ApiOperation(value = "分页查询用户列表", notes = "分页查询用户列表")
    public R getUserPage(@RequestBody @Validated UserPageDTO userPageDTO) {

        return userService.getUserPage(userPageDTO);
    }

    @PostMapping("/getId")
    @ApiOperation(value = "获取用户id", notes = "获取用户id")
    public List<Integer> getId(@RequestBody @Validated GetIdDTO getIdDTO) {
        return userService.getIds(getIdDTO);
    }

    @DeleteMapping("/deleteUser")
    @ApiOperation(value = "删除用户", notes = "删除用户")
    public R   deleteUser(@RequestParam("id") int id) {
        return R.Success();
    }

}
